package com.example.myapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;

import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Map;

public class LinearAdapter extends RecyclerView.Adapter<LinearAdapter.LinearAdapterHolder> {
    class LinearAdapterHolder extends RecyclerView.ViewHolder{
        TextView textView1,textView2,textView3,textView4,textView5,textView6;
        public LinearAdapterHolder(@NonNull @NotNull View itemView) {
            super(itemView);
            this.textView1 = itemView.findViewById(R.id.tv1);
            this.textView2 = itemView.findViewById(R.id.tv2);
            this.textView3 = itemView.findViewById(R.id.tv3);
            this.textView4 = itemView.findViewById(R.id.tv4);
            this.textView5 = itemView.findViewById(R.id.tv5);
            this.textView6 = itemView.findViewById(R.id.tv6);
        }
    }
    private Context context;
    private List<Map> listMap;

    public LinearAdapter(Context context, List<Map> listMap) {
        this.context = context;
        this.listMap = listMap;
    }

    @NonNull
    @NotNull
    @Override
    //设置视图绑定
    public LinearAdapter.LinearAdapterHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.linear_adapter_view, null);
        return new LinearAdapterHolder(inflate);
    }

    @Override
    //设置数据
    public void onBindViewHolder(@NonNull @NotNull LinearAdapter.LinearAdapterHolder holder, int position) {
        holder.textView1.setText(listMap.get(position).get("id")==null?null: listMap.get(position).get("id").toString());
        holder.textView2.setText(listMap.get(position).get("name")==null?null: listMap.get(position).get("name").toString());
        holder.textView3.setText(listMap.get(position).get("age")==null?null: listMap.get(position).get("age").toString());
        holder.textView4.setText(listMap.get(position).get("phone")==null?null: listMap.get(position).get("phone").toString());
        holder.textView5.setText(listMap.get(position).get("create_time")==null?null: listMap.get(position).get("create_time").toString());
        holder.textView6.setText(listMap.get(position).get("update_time")==null?null: listMap.get(position).get("update_time").toString());
    }

    @Override
    //给别 条条目 添加东西
    public int getItemViewType(int position) {

        return super.getItemViewType(position);
    }

    @Override
    public int getItemCount() {
        return listMap.size();
    }
}
